// packageF/others/customerCenter/customerCenterUser/customerCenterUser.js
const app = getApp();
const skinBehavior = require('../../../../utils/themeSkin/skinBehavior');
Page({
  behaviors: [skinBehavior],
  /**
   * 页面的初始数据
   */
  data: {
    userDataUrl: "plugin.customer-center.frontend.controllers.customer.get-customer",
    getConfig: {
      member_id: '',
      income_statistic_type: 0
    }, //企业微信公共参数

    memberInfo: {}, // 会员信息
    income_statistic: [], // 收入信息
    tags: [], // 标签列表
    actions: [], // 企业标签
    navActive: 0,
    addTagText: '',
    showAddTagPop: false,
    showAddSheet: false,
    income_statistic_type: "0",

    tabList: ['会员详情', 'Ta的客户', '订单列表', '收入详情', 'Ta的购物车', '优惠券', '商品收藏', '浏览足迹'],
    showChild: false,
    basicColor:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.id) {
      this.setData({
        'getConfig.member_id': options.id
      })
    }
    this.getUserData();
    wx.setNavigationBarTitle({
      title: '用户信息',
    })
    try {
      let basicColor = wx.getStorageSync('yz_basic_info').theme_color;
      let language = wx.getStorageSync("langIndex");
      this.setData({
        language: language.en,
        basicColor:basicColor
      })
    } catch (error) {
      console.log(error)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    let name = this.componentName();
    if(name == 'orderList' || name == 'browseRecord') return
    let child = this.selectComponent(`#${name}`);
    if (child) {
      if (!child.data.finished) {
        child.loadMore();
      }
    }

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  componentName() {
    switch (this.data.navActive) {
      case 1:
        return "myCustomer";
      case 2:
        return "orderList";
      case 3:
        return "revenueDetails";
      case 4:
        return "myCart";
      case 5:
        return "goodsCoupon";
      case 6:
        return "myFavorite";
      case 7:
        return "browseRecord";
    }
  },
  getUserData() {
    let urlStr = app.getNetAddresss(this.data.userDataUrl);
    app._postNetWork({
      url: urlStr,
      showToastIn: false,
      data: this.data.getConfig,
      success: (resdata) => {
        let res = resdata.data
        if (res.result == 1) {
          if (res.data.member && res.data.member.hasAuth == 0) {
            wx.showModal({
              content: '暂无权限',
              success: (resdata) => {
                wx.navigateTo({
                  url: '/packageG/member_v2/member_v2',
                })
              }
            })
          }
          console.log(res, 'ddddddddddddd')
          this.setData({
            showChild: true,
            tags: res.data.member.has_many_tag,
            memberInfo: res.data.member,
            income_statistic: res.data.statistics
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  selectNav(e) {
    console.log(e)
    this.setData({
      navActive: e.detail.index
    })
  },
  selectTime(e) {
    this.setData({
      income_statistic_type: e.detail.name,
      'getConfig.income_statistic_type': e.detail.name
    })
    let urlStr = app.getNetAddresss(this.data.userDataUrl);
    app._postNetWork({
      url: urlStr,
      data: {...this.data.getConfig,income_statistic_type:this.data.income_statistic_type},
      success: (resdata) => {
        let res = resdata.data
        if (res.result == 1) {
          this.setData({
            income_statistic: res.data.statistics,
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  }
})